package com.voxel.sense.infomsg.module.firm.details;

import com.example.com.common.app.BasePresenter;
import com.example.com.common.factory.data.DataSource;
import com.example.com.common.utils.ToastUtil;
import cyy.example.com.facotry.model.api.BaseEntity;
import cyy.example.com.facotry.model.api.response.FirmListEntity;
import cyy.example.com.facotry.net.helper.FirmNetHelper;
import cyy.example.com.facotry.Factory;

import java.util.List;

/**
 * Created by ChenYiYao on 2018/7/17.
 */
public class FirmDetailPresenter extends BasePresenter<FirmDetailContract.View>
        implements FirmDetailContract.Presenter, DataSource.Callback<BaseEntity<List<FirmListEntity>>> {

    public FirmDetailPresenter(FirmDetailContract.View view) {
        super(view);
    }

    @Override
    public void start() {

    }

    @Override
    public void destroy() {

    }

    @Override
    public void doLoadData(String id) {
        mView.showLoading("");
        FirmNetHelper.getSpecialFirm(id, this);
    }


    @Override
    public void onDataNotAvailable(String strRes, int reqId) {
        if (mView == null)
            return;

    }

    @Override
    public void onDataLoaded(BaseEntity<List<FirmListEntity>> data, int reqId) {
        if (mView == null)
            return;
        mView.dimissLoading();
        if (data.isSuccess() && data.getData() != null && data.getData().size() > 0) {
            FirmListEntity firmListEntity = data.getData().get(0);
            mView.refreshBaseInfo(firmListEntity);
        } else {
            ToastUtil.showToastLong(Factory.app(), "加载数据失败");
        }
    }


}
